class Solution {
public:
    int longestConsecutive(vector<int>& nums) {
        int max_len=0;
        unordered_set<long long >u_set; 
        for(auto &x:nums)
        u_set.insert(x);
        for(auto & num:u_set)
        {
            if(u_set.find(num-1)==u_set.end())
            {
                int len=0;
                while(u_set.find(num+len)!=u_set.end())
                {
                    ++len;
                    max_len=max(max_len,len);
                }
            }
        }
        return max_len;
    }
};